Skip to content

Reuse CelExpressionFlatImpl evaluation state across non-concurrent Evaluate calls. - #2299

Open
copybara-service[bot] wants to merge 1 commit into
masterfrom
test_988498326
Open

copybara-service[bot] wants to merge 1 commit into
masterfrom
test_988498326

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Reuse CelExpressionFlatImpl evaluation state across non-concurrent Evaluate calls.

  • CelExpressionFlatImpl::Evaluate(activation, arena) reuses a cached
    FlatExpressionEvaluatorState when it is not already in use (claimed via
    std::atomic<bool> cached_state_in_use_). Concurrent callers fall back to
    the existing per-call InitializeState path, so thread safety is unchanged.
  • The cached state is created on first use with the caller's arena and
    rebound to the caller's arena on later calls via the new
    FlatExpressionEvaluatorState::SetArena(). It is Reset() before being
    released so no values outlive the call's arena.
  • This avoids allocating/freeing the evaluator state (value stack,
    comprehension slots, iterator stack) on every evaluation.

…aluate calls.

- `CelExpressionFlatImpl::Evaluate(activation, arena)` reuses a cached
  `FlatExpressionEvaluatorState` when it is not already in use (claimed via
  `std::atomic<bool> cached_state_in_use_`). Concurrent callers fall back to
  the existing per-call `InitializeState` path, so thread safety is unchanged.
- The cached state is created on first use with the caller's arena and
  rebound to the caller's arena on later calls via the new
  `FlatExpressionEvaluatorState::SetArena()`. It is `Reset()` before being
  released so no values outlive the call's arena.
- This avoids allocating/freeing the evaluator state (value stack,
  comprehension slots, iterator stack) on every evaluation.

PiperOrigin-RevId: 988498326
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants